<?php

/*
 * Action 4$
 * 
 * +1 Card
 * +2 Actions
 * Reveal the top 3 cards of your deck. Put the Actions back on top in any order and discard the rest.
 *
 */

class WanderingMinstrel extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Wandering Minstrel", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Card",
            "+2 Actions",
            "Reveal the top 3 cards of your deck. Put the Actions back on top in any order and discard the rest.");
    }

    public function play(Game $game, $isRealCard) {
        $drawed_cards = $game->drawCards(1);
        $game->addActions(2);
        ScreenDisplay::addScreenMessage($game, true, "get +2 actions  and draw " . nicePrint($drawed_cards), "gets +2 actions and draws " . sizeof($drawed_cards) . " cards");

        $revealed_cards = $game->removeCardsFromDrawDeck(3);
        $actions = array();
        $other = array();
        foreach ($revealed_cards as $card) {
            if ($card instanceof iAction) {
                $actions[] = $card;
            } else {
                $other[] = $card;
            }
        }

        ScreenDisplay::addScreenMessage($game, true, "reveal " . nicePrint($revealed_cards), "reveals " . ScreenDisplay::$LMSG);
        $game->discardTempDiscardCards($other);
        ScreenDisplay::addScreenMessage($game, false, ", discard " . nicePrint($other), ", discards " . ScreenDisplay::$LMSG);

        if (sizeof($actions) == 0) {
            ScreenDisplay::addScreenMessage($game, false, " and put back nothing ", " and put back nothing");
        } elseif (sizeof($actions) == 1) {
            $game->putCardOnTopOfDrawDeck($actions[0]);
            ScreenDisplay::addScreenMessage($game, false, " and put back " . nicePrint($actions[0]), " and put back " . ScreenDisplay::$LMSG);
        } else {
            $cards = MySocket::GetUserReply($game, Input_Reorder, $actions, -1, -1, null, "Put cards back in any order");
            ScreenDisplay::addScreenMessage($game, false, " and put back " . nicePrint($cards), " and put back " . nicePrint($actions));
            $cards = array_reverse($cards);
            foreach ($cards as $pbc) {
                $game->putCardOnTopOfDrawDeck($pbc);
            }
            $cards = array_reverse($cards);
        }
        $game->cardActionFinished();
        return true;
    }

}

?>